package com.city.ajax.pub;

import com.city.domain.pub.*;
import com.city.domain.supervise.*;
import com.city.service.city.CityCopnotePersonService;
import com.city.service.city.CityHouseinfoService;
import com.city.service.pub.*;
import com.city.service.supervise.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @deprecation: 公共接口,未完
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-22 14:18
 */
@RequestMapping("/ajax/search")
@RestController
public class PubSearchAjax {

    @Autowired
    private CityCopnotePersonService copnotePersonService;

    @Autowired
    private PubFilepathService filepathService;

    @Autowired
    private PubCountService countService;

    @Autowired
    private PubHouseinfoService pubHouseinfoService;

    @Autowired
    private CityHouseinfoService cityHouseinfoService;

    @Autowired
    private PubKeyPersonService keyPersonService;

    @Autowired
    private ImpThingService impThingService;

    @Autowired
    private ImpCategoryService impCategoryService;

    @Autowired
    private ImpOrganizationService impOrganizationService;

    @Autowired
    private ImpLocationService impLocationService;

    @Autowired
    private PubKeyTrajectoryService keyTrajectoryService;


    /**
     * @deprecation: 分页获取居民房屋信息记录
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/gethouseinfo-limit")
    @ResponseBody
    public Map<String,Object> findPubHouseinfoLimit(
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value ="limitNum") Integer limitNum)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", pubHouseinfoService.getHouseinfoLimit(limitPage, limitNum));
        map.put("res", "1");
        map.put("code", "成功");
        map.put("count",pubHouseinfoService.count());
        return map;
    }

    /**
     * @deprecation: 分页获取居民房屋信息记录
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getcityhouseinfo-limit")
    @ResponseBody
    public Map<String,Object> findCityHouseinfoLimit(
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value ="limitNum") Integer limitNum)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", cityHouseinfoService.getHouseinfoLimit(limitPage, limitNum));
        map.put("res", "1");
        map.put("count", cityHouseinfoService.count());
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 分页获取重点人记录
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param search 条件
     * @param status 状态
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getkeyperson-limit")
    @ResponseBody
    public Map<String,Object> findPubKeyPersonLimit(
            @RequestParam(value = "search", defaultValue = "null") String search,
            @RequestParam(value = "status", defaultValue = "0") Integer status,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value ="limitNum") Integer limitNum)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        PubKeyPerson pubKeyPerson = new PubKeyPerson();

        pubKeyPerson.setStatus(status);

       if(!"null".equals(search)){
            pubKeyPerson.setName(search);
            pubKeyPerson.setTellphone(search);
           map.put("data", keyPersonService.getKeyPersonLimit(limitPage, limitNum,status,search));
           map.put("res", "1");
           map.put("count", keyPersonService.count(pubKeyPerson));
           map.put("code", "成功");
           return map;
        }
        map.put("data", keyPersonService.getKeyPersonLimit(limitPage, limitNum,status));
        map.put("res", "1");
        map.put("count", keyPersonService.count(pubKeyPerson));
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 分页获取地点管理记录
     * @author: 肖丽娜
     * @param search 条件
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018/8/16 15:32
     */
    @PostMapping("/getimplocation-limit")
    @ResponseBody
    public Map<String,Object> findImpLocationLimit(
            @RequestParam(value = "search", defaultValue = "null") String search,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value = "limitNum") Integer limitNum
    )
    {
        Map<String, Object> map = new HashMap<String, Object>();
        ImpLocation impLocation = new ImpLocation();

     if (!"null".equals(search)){
            impLocation.setLoname(search);
            impLocation.setTellphone(search);
            map.put("data", impLocationService.getImpLocationLimit(limitPage,limitNum,search));
            map.put("res", "1");
            map.put("count",impLocationService.count(impLocation));
            map.put("code", "成功");
            return map;
        }

        map.put("data", impLocationService.getImpLocationLimit(limitPage,limitNum));
        map.put("res", "1");
        map.put("count",impLocationService.count(impLocation));
        map.put("code", "成功");
        return map;
    }



    /**
     * @deprecation: 分页获取物件管理记录
     * @author: 肖丽娜
     * @param search 条件
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018/8/16 15:32
     */
    @PostMapping("/getimpthing-limit")
    @ResponseBody
    public Map<String, Object> findImpThingLimit(
            @RequestParam(value = "search", defaultValue = "null") String search,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value = "limitNum") Integer limitNum
    )
    {
        Map<String, Object> map = new HashMap<String, Object>();
        ImpThing impThing = new ImpThing();

        if (!"null".equals(search)){
            impThing.setThing_name(search);
            impThing.setTellphone(search);

            map.put("data", impThingService.getImpThingLimit(limitPage,limitNum,search));
            map.put("res", "1");
            map.put("count", impThingService.count(impThing));
            map.put("code", "成功");
            return map;
        }
        map.put("data", impThingService.getImpThingLimit(limitPage,limitNum));
        map.put("res", "1");
        map.put("count", impThingService.count(impThing));
        map.put("code", "成功");
        return map;
    }



    /**
     * @deprecation: 分页获取事件分类管理记录
     * @author: 肖丽娜
     * @param search 条件
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018/8/16 15:32
     */

    @PostMapping("/getimpcategory-limit")
    @ResponseBody
    public Map<String,Object> findImpCategoryLimit(
            @RequestParam(value = "search", defaultValue = "null") String search,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value = "limitNum") Integer limitNum
    ){
        Map<String, Object> map = new HashMap<String, Object>();
        ImpCategory impCategory = new ImpCategory();

        if (!"null".equals(search)){
            impCategory.setEvent_name(search);
            impCategory.setTellphone(search);

            map.put("data", impCategoryService.getImpCategoryLimit(limitPage,limitNum,search));
            map.put("res","1");
            map.put("count",impCategoryService.count(impCategory));
            map.put("code", "成功");
            return map;
        }

        map.put("data", impCategoryService.getImpCategoryLimit(limitPage,limitNum));
        map.put("res","1");
        map.put("count",impCategoryService.count(impCategory));
        map.put("code", "成功");
        return map;
    }




    /**
     * @deprecation: 分页获取组织管理记录
     * @author: 肖丽娜
     * @param search 条件
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018/8/16 15:32
     */

    @PostMapping("/getimporganization-limit")
    @ResponseBody
    public Map<String,Object> findImpOrganizationLimit(
            @RequestParam(value = "search", defaultValue = "null") String search,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value = "limitNum") Integer limitNum
    )
    {
        Map<String, Object> map = new HashMap<String, Object>();
        ImpOrganization impOrganization = new ImpOrganization();

        if (!"null".equals(search)){
            impOrganization.setOrganize_name(search);
            impOrganization.setTellphone(search);
            map.put("data", impOrganizationService.getImpOrganizationLimit(limitPage,limitNum,search));
            map.put("res", "1");
            map.put("count",impOrganizationService.count(impOrganization));
            map.put("code", "成功");
            return map;
        }

        map.put("data", impOrganizationService.getImpOrganizationLimit(limitPage,limitNum));
        map.put("res", "1");
        map.put("count",impOrganizationService.count(impOrganization));
        map.put("code", "成功");
        return map;
    }





    /**
     * @deprecation: 获取某条民情日记中所涉及的受访人员
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param time 时间索引
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getcopnote-person")
    @ResponseBody
    public Map<String,Object> findCityCopnotePersonLimit(
            @RequestParam(value = "time") String time)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", copnotePersonService.getTime(time));
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }



    /**
     * @deprecation: 获取某表中某记录的关联文件
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param tableName 表的备注名称
     * @param idIndex 表中的time字段值
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getfile-index")
    @ResponseBody
    public Map<String,Object> findPubFilepathRecord(
            @RequestParam(value = "tableName") String tableName,
            @RequestParam(value = "idIndex") String idIndex)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", filepathService.getFileIdIndex(tableName, idIndex));
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 通用文件查询接口
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param pubFilepath 映射，应与实体类一致
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getfile-search")
    @ResponseBody
    public Map<String,Object> findPubFilepathAll(@RequestBody PubFilepath pubFilepath)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", filepathService.findAll(pubFilepath));
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 通用重点人查询
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getkeyperson-search")
    @ResponseBody
    public Map<String,Object> findPubKeyPersonAll(@RequestParam(value = "search", defaultValue = "null") String search)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        PubKeyPerson pubKeyPerson = new PubKeyPerson();
        pubKeyPerson.setStatus(1);

       if(!"null".equals(search)){
            pubKeyPerson.setName(search);
            pubKeyPerson.setTellphone(search);
        }
        List<PubKeyPerson> list =  keyPersonService.findAll(pubKeyPerson);

        map.put("data",list);
        map.put("count", list.size());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }


    /**
     * @deprecation: 通用重点地点查询
     * @author: 肖丽娜
     * @date: 2018-08-20 16:32
     */
    @PostMapping("/getimplocation-search")
    @ResponseBody
    public Map<String, Object> findImpLocationAll(@RequestParam(value = "search", defaultValue = "null") String search)
    {
        Map<String,Object> map = new HashMap<String,Object>();
        ImpLocation impLocation = new ImpLocation();
        if (!"null".equals(search)){
            impLocation.setLoname(search);
            impLocation.setManame(search);
            impLocation.setTellphone(search);
        }
        List<ImpLocation> list = impLocationService.findAll(impLocation);

        map.put("data",list);
        map.put("count", list.size());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 通用重点事件分类查询
     * @author: 肖丽娜
     * @date: 2018-08-20 16:32
     */
    @PostMapping("/getimpcategory-search")
    @ResponseBody
    public Map<String, Object> findImpCategoryAll(@RequestParam(value = "search", defaultValue = "null") String search)
    {
        Map<String,Object> map = new HashMap<String,Object>();
        ImpCategory impCategory = new ImpCategory();
        if (!"null".equals(search)){
            impCategory.setEvent_name(search);
            impCategory.setmaname(search);
            impCategory.setTellphone(search);
        }
        List<ImpCategory> list = impCategoryService.findAll(impCategory);

        map.put("data",list);
        map.put("count", list.size());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }

    /**
     * @deprecation: 通用重点物件管理查询
     * @author: 肖丽娜
     * @date: 2018-08-20 16:32
     */
    @PostMapping("/getimpthing-search")
    @ResponseBody
    public Map<String, Object> findImpThingAll(@RequestParam(value = "search", defaultValue = "null") String search)
    {
        Map<String,Object> map = new HashMap<String,Object>();
        ImpThing impThing = new ImpThing();
        if (!"null".equals(search)){
            impThing.setThing_name(search);
            impThing.setManager(search);
            impThing.setTellphone(search);
        }
        List<ImpThing> list = impThingService.findAll(impThing);

        map.put("data",list);
        map.put("count", list.size());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }


    /**
     * @deprecation: 通用重点组织查询
     * @author: 肖丽娜
     * @date: 2018-08-20 16:32
     */
    @PostMapping("/getimporganization-search")
    @ResponseBody
    public Map<String, Object> findOrganizationAll(@RequestParam(value = "search", defaultValue = "null") String search)
    {
        Map<String,Object> map = new HashMap<String,Object>();
        ImpOrganization impOrganization = new ImpOrganization();
        if (!"null".equals(search)){
            impOrganization.setOrganize_name(search);
            impOrganization.setManager(search);
            impOrganization.setTellphone(search);
        }
        List<ImpOrganization> list = impOrganizationService.findAll(impOrganization);

        map.put("data",list);
        map.put("count", list.size());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }



    /**
     * @deprecation: 通用统计查询接口
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param pubCount 映射，应与实体类一致
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getpubcount-search")
    @ResponseBody
    public Map<String,Object> findPubCountAll(@RequestBody PubCount pubCount)
    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", countService.getAll(pubCount));
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }


    /**
     * @deprecation: 获取某表中某记录的GIS信息
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @param tableName 表的备注名称
     * @param idIndex 表中的关联字段值
     * @param limitPage 当前页
     * @param limitNum 每页数量
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/getgis")
    @ResponseBody
    public Map<String,Object> findGISInfo(
            @RequestParam(value = "tableName") String tableName,
            @RequestParam(value = "idIndex") String idIndex,
            @RequestParam(value = "limitPage") Integer limitPage,
            @RequestParam(value ="limitNum") Integer limitNum)

    {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", keyTrajectoryService.getPubKeyTrajectoryLimit(tableName, idIndex, limitPage, limitNum));
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }


    /**
     * @deprecation: 获取居民房屋GIS信息
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @date: 2018-07-20 16:32
     */
    @PostMapping("/gethouseinfo-gis")
    @ResponseBody
    public Map<String,Object> findPubHouseinfoGis(){
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("data", pubHouseinfoService.getHouseinfoGIS());
        map.put("res", "1");
        map.put("code", "成功");
        return map;
    }


    /**
     * @deprecation: 内部接口,不可乱动
     * @dmail: 398521613@qq.com
     * @author: L-H
     * @date: 2018-07-20 16:32
     */
//    @PostMapping("/test")
//    @ResponseBody
//    public String test(){
//        List<CityTown> towns = cityTownService.findName("1");
//        List<PubCount> counts = countService.getAll(new PubCount());
//
//        System.out.println(towns.size());
//
//        for(CityTown cityTown : towns){
//            List<CityVillage> villages = cityVillageService.findName(cityTown.getTownId());
//            System.out.println(villages.size());
//            for(CityVillage cityVillage : villages){
//
//                for(PubCount count : counts){
//                    PubCount pubCount = new PubCount();
//                    pubCount.setTown(cityTown.getTownName());
//                    pubCount.setVillage(cityVillage.getVillageName());
//                    pubCount.setCountRes(0);
//                    pubCount.setName(count.getName());
//                    saveService.save(pubCount);
//                }
//
//            }
//        }
//
//        return null;
//    }

}
